// file转base64
export const fileToBase64 = async file => {
  let reader = new FileReader();
  let fn = function () {
    return new Promise(resolve => {
      reader.onload = function () {
        resolve(this.result);
      };
      reader.onerror = function () {
        resolve(null);
      };
    });
  };
  reader.readAsDataURL(file.raw);
  return fn();
};

// file转DataURL
export const fileToDataURL = (files = []) => {
  let newFiles = [];
  for (let i = 0; i < files.length; i++) {
    const item = files[i];
    newFiles.push({
      name: item.name.substring(0, item.name.lastIndexOf('.')),
      type: item.name.substring(item.name.lastIndexOf('.'), item.name.length),
      size: item.size,
      dataUrl: URL.createObjectURL(item),
    });
  }
  return newFiles;
};
